package _4JianZaoZhe;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * @Meal: 食物的添加 获取 查找类
 * @author: ZBoHang
 * @time: 2021/9/7 11:36
 */
public class Meal {

    private static final List<Item> items = new ArrayList<>();

    public void addItem(Item item) {
        items.add(item);
    }

    public float getCost() {
        float cost = 0;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    public void showItems() {
        items.forEach(new Consumer<Item>() {
            @Override
            public void accept(Item item) {
                System.out.print("名称" + item.name());
                System.out.print("  -->包装" + item.packing().pack());
                System.out.println("  -->>价格" + item.price());
            }
        });
    }
}
